﻿using System;
using System.IO;

namespace Atha
{
	public class TestScriptFileReader : ITestScriptReader
	{
		private readonly string _filePath;

		public TestScriptFileReader(string filePath)
		{
			// TODO: Verify file path

			this._filePath = filePath;
		}

		/// <summary>
		/// Gets the script.
		/// </summary>
		/// <returns></returns>
		public void GetScript(Action<ITestScript> callback)
		{
			// TODO: Handle no language mapping

			string content = File.ReadAllText(this._filePath);
			string ext = Path.GetExtension(this._filePath);
			string language = null;

			switch (ext.ToUpperInvariant())
			{
				case ".PY":
					language = "IronPython";
					break;
				case ".RB":
					language = "IronRuby";
					break;
				case ".PS1":
					language = "PowerShell";
					break;
				case ".CSHTML":
				case ".VBHTML":
					language = "Razor";
					break;
			}

			var script = new BasicTestScript(language, this._filePath, content);

			callback(script);
		}
	}
}
